<?php

namespace App\Http\Controllers\PC\Code;
use Session;
use Illuminate\Http\Request;
use App\Http\Service\User\UserService;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class CodeController extends Controller
{
    public function getCode(Request $request)
    {
        $validateCode = $request->input('validateCode');
        $data = [];
        $where=[];

        $code = Session::get('VERIFICATION');

        $validateCode = strtolower($validateCode);
        //   检测验证码
        $validateCode = md5($validateCode.'niumokeji888');


        if($code != $validateCode)
        {
            $return = array(
                'code' => -1,
                'msg' => "非法的验证码",
                'data' => array()
            );
            return response()->json($return);
        }

        $data = [];
        $where=[];
        $where['mobile']=$request->input('mobile');

        $where['ip'] = $request->getClientIp();
        $where['action'] = $request->input('action');
        $where['source'] = 'www.niumoip.com';
        $where['terminal'] = 'PC';


        $user = new UserService();
        $data = $user->getCode($where);
        return $data;

    }

    public function getIp()
    {

        $ip = $_SERVER["REMOTE_ADDR"];
        echo $ip;
    }
    
}
